<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h3>组件添加v-model</h3>
      <p>{{ msg }}</p>
      <!-- <app-child :value="msg" @input="fn"></app-child> -->
      <app-child v-model="msg"></app-child>
    </div>

    <script src="../Vue.js"></script>
    <script>
      Vue.component("app-child", {
        props: ["value"],
        template: `
          <input type="text" :value="value" @input="fn" />
        `,
        methods: {
          fn(e) {
            this.$emit("input", e.target.value);
          },
        },
      });
      new Vue({
        el: "#app",
        data: {
          msg: "123",
        },
        // methods: {
        //   fn(v) {
        //     this.msg = v;
        //   },
        // },
      });
    </script>
  </body>
</html>
